package com.manor.main.dialog

import android.content.Context
import android.graphics.Color
import android.graphics.drawable.Drawable
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.CenterCrop
import com.bumptech.glide.request.RequestOptions
import com.lxj.xpopup.core.CenterPopupView
import com.lxj.xpopup.util.XPopupUtils
import com.noober.background.drawable.DrawableCreator
import com.manor.common.bean.UserNBean
import com.manor.common.utils.DpUtil
import com.manor.main.R
import kotlinx.android.synthetic.main.popup_medal_show.view.*
import kotlin.math.roundToInt

/**
 *


 * @date  2020/5/18  14:51
 * @version 1.0
 */
class MedalShowPopup (context: Context, val mBean: UserNBean.MedalBean?) : CenterPopupView(context) {

    override fun getImplLayoutId(): Int {
        return R.layout.popup_medal_show
    }

    override fun onCreate() {
        super.onCreate()
        mBean?.run {
            tvName.text = name
            tvContent.text = detail
            Glide.with(context)
                    .load(icon)
                    .apply(RequestOptions().transform( CenterCrop()))
                    .into(ivImage)
        }
        ivDismiss.setOnClickListener { dismiss() }
    }


    override fun getBackground(): Drawable {
        return DrawableCreator.Builder()
                .setCornersRadius(DpUtil.dp2px(16).toFloat())
                .setSolidColor(Color.parseColor("#ffffffff"))
                .build()
    }

    override fun getMaxHeight(): Int {
        return (XPopupUtils.getWindowHeight(context) * .50f).roundToInt()
    }

    override fun getMaxWidth(): Int {
        return (XPopupUtils.getWindowWidth(context) * .90f).roundToInt()
    }

}